package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
import com.miyake.dsp.osa.realinstrument.HigeSearch;

@LabUiAnnotation(caption="Hige Detector")
public class HigeDetectorWrapper extends Calculator {
	public static final String INPUT_X = "Input X";
	public static final String INPUT_Y = "Input Y";
	public static final String OUTPUT_X = "Output X";
	public static final String OUTPUT_NOISE = "Output Noise";
	
	public HigeDetectorWrapper() {
		initInput(INPUT_X);
		initInput(INPUT_Y);
		initOutput(OUTPUT_X);
		initOutput(OUTPUT_NOISE);
	}
	
	@Override
	public void process() {
		double[] y = getInput(INPUT_Y).getRealPart();
		double[] x;
		if (getInput(INPUT_X) == null) {
			x = new double[y.length];
			for (int i = 0; i < x.length; i++) {
				x[i] = i;
			}
		}
		else {
			x = getInput(INPUT_X).getRealPart();
		}
		
		HigeSearch search = new HigeSearch(y);
		int[] indexes = search.getHigeIndexes();
		double[] v = new double[indexes.length];
		for (int i = 0; i < indexes.length; i++) {
			v[i] = indexes[i];
		}
		setOutput(OUTPUT_X, v);
		setOutput(OUTPUT_NOISE, search.getPeakSearchFloor());
	}

	@Override
	public Object getSetting() {
		// TODO Auto-generated method stub
		return null;
	}

}
